Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
C# / VB.NET - [C#] Aiuto su tema creato da me, su file dll
Forum - C# / VB.NET - [C#] Aiuto su tema creato da me, su file dll

Avatar
Sevenjeak (Normal User)
Pro


Messaggi: 91
Iscritto: 03/01/2012

Segnala al moderatore
Postato alle 18:49
Martedì, 11/10/2016
Salve,

Sto cercando, da più di un giorno, anche cercando su internet, ma senza risultati, di creare un tema su file dll

Volendo creare un tema per il mio progetto, ho creato, nel progetto un file contenente questo codice:

Codice sorgente - presumibilmente C#

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Drawing.Drawing2D;
  6. using System.Drawing.Imaging;
  7. using System.IO;
  8. using System.Runtime.InteropServices;
  9. using System.Windows.Forms;
  10.  
  11. namespace cnTheme
  12. {
  13.     abstract class cnControl : ContainerControl
  14.     {
  15.         protected Bitmap _Bitmap;
  16.         protected Graphics _Graphics;
  17.  
  18.         protected SolidBrush brushTitle = new SolidBrush(Color.FromArgb(103, 112, 120));
  19.         protected Color bgControl = Color.FromArgb(191, 203, 222);
  20.         protected Color borderColor = SystemColors.ActiveBorder;
  21.         protected Color borderColorActive = SystemColors.ActiveCaption;
  22.  
  23.         protected bool elementFocus, mouseHover, mousePress = false;
  24.         protected int pointerX, pointerY;
  25.  
  26.         public cnControl()
  27.         {
  28.             SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
  29.         }
  30.  
  31.         [DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")]
  32.         private static extern IntPtr CreateRoundRectRgn
  33.         (
  34.             int nLeftRect, // x-coordinate of upper-left corner
  35.             int nTopRect, // y-coordinate of upper-left corner
  36.             int nRightRect, // x-coordinate of lower-right corner
  37.             int nBottomRect, // y-coordinate of lower-right corner
  38.             int nWidthEllipse, // height of ellipse
  39.             int nHeightEllipse // width Of ellipse
  40.         );
  41.  
  42.         protected void DrawCorner(PaintEventArgs e, Border3DStyle style)
  43.         {
  44.             Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(0, 0, Width, Height, 10, 10));
  45.  
  46.             Rectangle borderCorner = ClientRectangle;
  47.  
  48.             ControlPaint.DrawBorder3D(e.Graphics, borderCorner, style);
  49.         }
  50.     }
  51.  
  52.     class cnForm : cnControl
  53.     {
  54.         private Point lastPoint;
  55.  
  56.         public cnForm()
  57.         {
  58.             Dock = DockStyle.Fill;
  59.             BackColor = bgControl;
  60.             Padding = new Padding(3, 25, 3, 3);
  61.         }
  62.  
  63.         protected sealed override void OnHandleCreated(EventArgs e)
  64.         {
  65.             base.OnHandleCreated(e);
  66.  
  67.             FindForm().BackColor = SystemColors.Control;
  68.             FindForm().TransparencyKey = SystemColors.Control;
  69.             FindForm().FormBorderStyle = 0;
  70.         }
  71.  
  72.         protected override void OnMouseDown(MouseEventArgs e)
  73.         {
  74.             base.OnMouseDown(e);
  75.  
  76.             this.lastPoint = e.Location;
  77.         }
  78.  
  79.         protected override void OnMouseUp(MouseEventArgs e)
  80.         {
  81.             base.OnMouseUp(e);
  82.         }
  83.  
  84.         protected override void OnMouseMove(MouseEventArgs e)
  85.         {
  86.             base.OnMouseMove(e);
  87.  
  88.             pointerX = e.X;
  89.             pointerY = e.Y;
  90.  
  91.             if (e.Button == MouseButtons.Left)
  92.             {
  93.                 FindForm().Left += e.X - lastPoint.X;
  94.                 FindForm().Top += e.Y - lastPoint.Y;
  95.             }
  96.  
  97.             Invalidate();
  98.         }
  99.  
  100.         protected override void OnMouseClick(MouseEventArgs e)
  101.         {
  102.             base.OnMouseClick(e);
  103.  
  104.             #region "Form Control Button"
  105.  
  106.             /* ---------------------- SET CLOSE BUTTON ------------------------ */
  107.             Rectangle ButtonCloseRange = new Rectangle(Width - 23, 6, 15, 17);
  108.  
  109.             if (ButtonCloseRange.Contains(new Point(pointerX, pointerY)) && e.Button == MouseButtons.Left) FindForm().Close();
  110.  
  111.             /* ---------------------- SET MAXIMEZE BUTTON ------------------------ */
  112.             Rectangle ButtonMinMaxRange = new Rectangle(Width - 52, 6, 13, 15);
  113.  
  114.             if (ButtonMinMaxRange.Contains(new Point(pointerX, pointerY)) && e.Button == MouseButtons.Left)
  115.             {
  116.                 if (FindForm().WindowState == FormWindowState.Maximized)
  117.                     FindForm().WindowState = FormWindowState.Normal;
  118.                 else
  119.                     FindForm().WindowState = FormWindowState.Maximized;
  120.             }
  121.  
  122.             /* ---------------------- SET MINIMEZE BUTTON ------------------------ */
  123.             Rectangle ButtonMinRange = new Rectangle(Width - 76, 6, 13, 15);
  124.  
  125.             if (ButtonMinRange.Contains(new Point(pointerX, pointerY)) && e.Button == MouseButtons.Left) FindForm().WindowState = FormWindowState.Minimized;
  126.  
  127.             #endregion
  128.         }
  129.  
  130.         protected override void OnPaint(PaintEventArgs e)
  131.         {
  132.             base.OnPaint(e);
  133.  
  134.             _Bitmap = new Bitmap(Width, Height);
  135.             _Graphics = Graphics.FromImage(_Bitmap);
  136.  
  137.             DrawCorner(e, Border3DStyle.Raised);
  138.  
  139.             _Graphics.DrawIcon(new Icon(FindForm().Icon, 10, 10), 10, 10);
  140.             _Graphics.DrawString(FindForm().Text, new Font("arial", 10), brushTitle, 28, 10);
  141.  
  142.             #region "Control button"
  143.  
  144.             /* ---------------------- SET CLOSE BUTTON ------------------------ */
  145.             Rectangle ButtonCloseRange = new Rectangle(Width - 26, 6, 13, 15);
  146.             //_Graphics.DrawRectangle(New Pen(New SolidBrush(Color.Red)), ButtonCloseRange);
  147.  
  148.             if (ButtonCloseRange.Contains(new Point(pointerX, pointerY)))
  149.                 _Graphics.DrawImage(new Bitmap(cnTheme.Properties.Resources.close_hover), new Point(Width - 25, 9));
  150.             else
  151.                 _Graphics.DrawImage(new Bitmap(cnTheme.Properties.Resources.close), new Point(Width - 25, 9));
  152.  
  153.             /* ---------------------- SET MAXIMEZE BUTTON -------------------- */
  154.             Rectangle ButtonMinMaxRange = new Rectangle(Width - 52, 6, 13, 15);
  155.             //_Graphics.DrawRectangle(New Pen(New SolidBrush(Color.Orange)), ButtonMinMaxRange);
  156.  
  157.             if (ButtonMinMaxRange.Contains(new Point(pointerX, pointerY)))
  158.                 _Graphics.DrawImage(new Bitmap(cnTheme.Properties.Resources.minmax_hover), new Point(Width - 50, 9));
  159.             else
  160.                 _Graphics.DrawImage(new Bitmap(cnTheme.Properties.Resources.minmax), new Point(Width - 50, 9));
  161.  
  162.  
  163.             /* ---------------------- SET MINIMEZE BUTTON -------------------- */
  164.             Rectangle ButtonMinRange = new Rectangle(Width - 76, 6, 13, 15);
  165.             //_Graphics.DrawRectangle(New Pen(New SolidBrush(Color.Orange)), ButtonMinRange);
  166.  
  167.             if (ButtonMinRange.Contains(new Point(pointerX, pointerY)))
  168.                 _Graphics.DrawImage(new Bitmap(cnTheme.Properties.Resources.minimeze_hover), new Point(Width - 75, 9));
  169.             else
  170.                 _Graphics.DrawImage(new Bitmap(cnTheme.Properties.Resources.minimeze), new Point(Width - 75, 9));
  171.  
  172.             #endregion
  173.  
  174.             e.Graphics.DrawImage(_Bitmap, 0, 0);
  175.             _Bitmap.Dispose();
  176.             _Graphics.Dispose();
  177.         }
  178.     }
  179.  
  180.     class cnMainTabs : TabControl
  181.     {
  182.         private Bitmap _Bitmap = null;
  183.         private Graphics _Graphics = null;
  184.  
  185.         public cnMainTabs()
  186.         {
  187.             SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
  188.  
  189.             Dock = DockStyle.Fill;
  190.         }
  191.  
  192.         protected override void CreateHandle()
  193.         {
  194.             base.CreateHandle();
  195.  
  196.             Location = new Point(7, 30);
  197.             Size = new Size(FindForm().Width - 13, FindForm().Height - 35);
  198.             SizeMode = TabSizeMode.Fixed;
  199.             ItemSize = new Size(212, 27);
  200.             DrawMode = TabDrawMode.OwnerDrawFixed;
  201.         }
  202.  
  203.         protected override void OnPaint(PaintEventArgs e)
  204.         {
  205.             base.OnPaint(e);
  206.  
  207.             _Bitmap = new Bitmap(Width, Height);
  208.             _Graphics = Graphics.FromImage(_Bitmap);
  209.  
  210.             _Graphics.Clear(Color.FromArgb(191, 203, 222));
  211.  
  212.             Point CornerPoint = new Point(DisplayRectangle.X - 1, DisplayRectangle.Y - 1);
  213.             Size CornerSize = new Size(DisplayRectangle.Width + 2, DisplayRectangle.Height + 2);
  214.  
  215.             _Graphics.FillRectangle(new SolidBrush(Color.FromArgb(150, 150, 150)), new Rectangle(CornerPoint, CornerSize));
  216.  
  217.             for (int i = 0; i < TabCount; i++)
  218.             {
  219.  
  220.                 if (i == SelectedIndex)
  221.                     _Graphics.DrawImage(new Bitmap(cnTheme.Properties.Resources.header_tab), new Point(GetTabRect(i).X, GetTabRect(i).Y));
  222.                 else
  223.                     _Graphics.DrawImage(new Bitmap(cnTheme.Properties.Resources.header_tab_inactive), new Point(GetTabRect(i).X, GetTabRect(i).Y));
  224.  
  225.                 if (TabPages[i].Text != "")
  226.                 {
  227.                     String tabText = "";
  228.  
  229.                     if (TabPages[i].Text.Length > 25)
  230.                         tabText = TabPages[i].Text.Substring(0, 25);
  231.                     else
  232.                         tabText = TabPages[i].Text;
  233.  
  234.                     _Graphics.DrawString(tabText, new Font("Segoe UI", 9), new SolidBrush(Color.Gray), GetTabRect(i).X + 30, GetTabRect(i).Y + 5);
  235.                 }
  236.                 else
  237.                 {
  238.                     _Graphics.DrawString("Nuova scheda", new Font("Segoe UI", 9), new SolidBrush(Color.Gray), GetTabRect(i).X + 30, GetTabRect(i).Y + 5);
  239.                 }
  240.             }
  241.  
  242.             e.Graphics.DrawImage(_Bitmap, 0, 0);
  243.  
  244.             _Graphics.Dispose();
  245.             _Bitmap.Dispose();
  246.         }
  247.     }
  248.  
  249.     class cnPageBar : cnControl
  250.     {
  251.  
  252.         public cnPageBar()
  253.         {
  254.             Dock = DockStyle.Top;
  255.             BackColor = Color.FromArgb(230, 230, 230);
  256.             Size = new Size(968, 30);
  257.         }
  258.  
  259.         protected override void OnPaint(PaintEventArgs e)
  260.         {
  261.  
  262.         }
  263.     }
  264.  
  265.     class cnBarButton : cnControl
  266.     {
  267.         private Image _image;
  268.  
  269.         public Image image
  270.         {
  271.             get
  272.             {
  273.                 return _image;
  274.             }
  275.             set
  276.             {
  277.                 _image = value;
  278.                 Invalidate();
  279.             }
  280.         }
  281.  
  282.         public cnBarButton()
  283.         {
  284.             Size = new Size(26, 23);
  285.             BackColor = Color.FromArgb(230, 230, 230);
  286.         }
  287.  
  288.         protected override void OnPaint(PaintEventArgs e)
  289.         {
  290.             base.OnPaint(e);
  291.  
  292.             _Bitmap = new Bitmap(Height, Width);
  293.             _Graphics = Graphics.FromImage(_Bitmap);
  294.  
  295.             _Graphics.DrawImage(new Bitmap(_image, 16, 16), 3, 3);
  296.  
  297.             if (mouseHover && Enabled)
  298.                 DrawCorner(e, Border3DStyle.Raised);
  299.  
  300.             e.Graphics.DrawImage(_Bitmap, 0, 0);
  301.  
  302.             _Graphics.Dispose();
  303.             _Bitmap.Dispose();
  304.         }
  305.  
  306.         protected override void OnMouseEnter(EventArgs e)
  307.         {
  308.             base.OnMouseHover(e);
  309.  
  310.             mouseHover = true;
  311.             Invalidate();
  312.         }
  313.  
  314.         protected override void OnMouseLeave(EventArgs e)
  315.         {
  316.             base.OnMouseLeave(e);
  317.  
  318.             mouseHover = false;
  319.             Invalidate();
  320.         }
  321.  
  322.         protected override void OnMouseDown(MouseEventArgs e)
  323.         {
  324.             base.OnMouseDown(e);
  325.  
  326.             BackColor = Color.FromArgb(220, 220, 220);
  327.             mousePress = true;
  328.         }
  329.  
  330.         protected override void OnMouseUp(MouseEventArgs e)
  331.         {
  332.             base.OnMouseUp(e);
  333.  
  334.             BackColor = Color.FromArgb(230, 230, 230);
  335.             mousePress = false;
  336.         }
  337.     }
  338.  
  339.     class cnAdressBar : cnControl
  340.     {
  341.         private Icon iconBar;
  342.         public TextBox textBar = new TextBox();
  343.  
  344.         public Icon Icon
  345.         {
  346.             get
  347.             {
  348.                 return iconBar;
  349.             }
  350.             set
  351.             {
  352.                 iconBar = value;
  353.                 Invalidate();
  354.             }
  355.         }
  356.  
  357.         public override String Text
  358.         {
  359.             get
  360.             {
  361.                 return textBar.Text;
  362.             }
  363.             set
  364.             {
  365.                 textBar.Text = value;
  366.             }
  367.         }
  368.  
  369.         public cnAdressBar()
  370.         {
  371.             SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
  372.         }
  373.  
  374.         protected override void OnHandleCreated(EventArgs e)
  375.         {
  376.             base.OnHandleCreated(e);
  377.  
  378.             textBar.Dock = DockStyle.Fill;
  379.  
  380.             Controls.Add(textBar);
  381.         }
  382.  
  383.         protected override void OnPaint(PaintEventArgs e)
  384.         {
  385.             base.OnPaint(e);
  386.  
  387.             _Bitmap = new Bitmap(Width, Height);
  388.             _Graphics = Graphics.FromImage(_Bitmap);
  389.  
  390.             e.Graphics.DrawImage(_Bitmap, 0, 0);
  391.  
  392.             _Graphics.Dispose();
  393.             _Bitmap.Dispose();
  394.         }
  395.     }
  396. }



Che funziona benissimo, infatti, una volta compilato il codice mi vengono visualizzati i due componenti da me creati nella barra degli strumenti.

Successivamente, siccome vorrei inserire i seguenti componenti anche in altri progetti, ho pensato, di inserire questo codice in una libreria di classi, successivamente compilato in un file DLL, ma, una volta inserito in altri progetti, tramite riferimento, non mi viene creato nessun nuovo elemento nella casella degli strumenti, anche dopo aver compilato il progetto, come mai?

Non so se mi sono spiegato.

EDIT:

Quando vado a selezionale la dll per aggiungere nuovi elementi nella barra degli strumenti, mi dice semplicemente che, la dll selezionato non ha nessun elemento da poter aggiungere alla barra degli strumenti.

Ultima modifica effettuata da Sevenjeak il 13/10/2016 alle 11:51
PM Quote
Avatar
Thejuster (Admin)
Guru^2


Messaggi: 2309
Iscritto: 04/05/2008

Segnala al moderatore
Postato alle 8:39
Venerdì, 14/10/2016
Prova ad usare un componente.

Normalmente si dovrebbe creare un componente ed un Interfaccia.


Questo può esserti di aiuto
https://msdn.microsoft.com/en-us/library/system.componentmo ...


https://mire.forumfree.it/ - Mire Engine
C# UI Designer
PM Quote
Avatar
Sevenjeak (Normal User)
Pro


Messaggi: 91
Iscritto: 03/01/2012

Segnala al moderatore
Postato alle 22:33
Sabato, 15/10/2016
Non so se era quello che intendevi, ma ho provato ad aggiungere semplicemente l'interfaccia alla classe astratta cnControl, modificando la definizione della classe astratta in questo modo:

Codice sorgente - presumibilmente C# / VB.NET

  1. abstract class cnControl : ContainerControl, IComponent



Ma il risultato è lo stesso, non funziona.

Era quello che intendevi te? o intendevi modificare il codice in altro modo?

Ho provato anche ad implementare l'interfaccia direttamente nelle classi che estendono la classe astratta, anche se credo sia la stessa cosa, ed il risultato non cambia uguale.

Non saprei proprio come risolvere, ho provato a cercare su internet il codice sorgente di un thema su un file dll, ma niente, trovo solo temi da aggiungere il un file all'interno del progetto, che, come il mio, non funzionano, se inserito in una dll.

Ultima modifica effettuata da Sevenjeak il 15/10/2016 alle 22:35
PM Quote
Avatar
Thejuster (Admin)
Guru^2


Messaggi: 2309
Iscritto: 04/05/2008

Segnala al moderatore
Postato alle 8:43
Martedì, 18/10/2016
La cosa è molto strana concordo.

Ho provato anche io a fare un qualcosa del genere.
Ma i controlli container nella libreria non vengono visualizzati nella barra degli strumenti.
cosa al quanto strana. e non poco..


https://mire.forumfree.it/ - Mire Engine
C# UI Designer
PM Quote
Avatar
Sevenjeak (Normal User)
Pro


Messaggi: 91
Iscritto: 03/01/2012

Segnala al moderatore
Postato alle 10:42
Mercoledì, 19/10/2016
In effetti si, anche perché la classe cnMainTabs estende la classe TabControl, il qui elemento è già presente nella casella degli strumenti.

Ho provato anche creando un nuovo progetto libreria di classi aggiungendo all'interno dei Controlli utenti, creando cosi il tutto utilizzando l'interfaccia grafica è no da codice, utilizzando la stessa procedura che si vede in questo video:

https://www.youtube.com/watch?v=pma4FzTz0Jk

ma niente, proprio non va, eppure, il tema, fin quando sta nel progetto me lo applica, è quando esporto il tutto in un file dll è che non funziona.

Non saprei che dire, intanto sto cercando altre soluzione su internet, è possibile che sia l'ide che uso? uso Visual Studio Express 2015, in particolare la dll è scritta con Visual C# 2015

Ultima modifica effettuata da Sevenjeak il 19/10/2016 alle 10:46
PM Quote
Avatar
Thejuster (Admin)
Guru^2


Messaggi: 2309
Iscritto: 04/05/2008

Segnala al moderatore
Postato alle 14:23
Mercoledì, 19/10/2016
no io ho vs2010 è ho lo stesso e medesimo problema.

inserendo il file come classe all'interno di un progetto funziona.
Ma esportandolo come libreria non funziona.

forse serve qualche parametro durante la compilazione non saprei.
E' la prima volta che mi capita qualcosa del genere 8-|


https://mire.forumfree.it/ - Mire Engine
C# UI Designer
PM Quote
Avatar
Sevenjeak (Normal User)
Pro


Messaggi: 91
Iscritto: 03/01/2012

Segnala al moderatore
Postato alle 12:25
Venerdì, 28/10/2016
Navigando su internet, ho trovato questo progetto:

https://github.com/IgnaceMaes/MaterialSkin

Premetto che ancora non ho visto bene tutto il codice, ma sto cercando di capire cosa sbaglio nel mio codice analizzando lo skin nel link qui sopra, spero di capirci qualche cosa :)

RISOLTO:

A Quando pare il codice andava benissimo, infatti aggiungendo il tema linkato qui sopra nello stesso modo ( tasto destro su la toolbox > seleziona elemento ) non mi funziona, ma se, trascino la dll ( drag and drop ) direttamente sulla toolbook mi funziona benissimo, lo stesso vale per la libreria fatta da me ( senza aver dovuto mettere mano sul codice ), qualcuno di voi sa spiegare come mai con il drag and drop funzioni e dal menu seleziona elementi non funzioni?

In ogni caso, grazie a tutti per le risposte.

Ultima modifica effettuata da Sevenjeak il 03/11/2016 alle 9:52
PM Quote